/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package vernotte.alexandre.idm.projet.model.kaosgoalmodel.KaosGoalModel.impl;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;

import org.eclipse.emf.ecore.util.EObjectWithInverseResolvingEList;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.ecore.util.InternalEList;

import vernotte.alexandre.idm.projet.model.kaosgoalmodel.KaosGoalModel.Alternative;
import vernotte.alexandre.idm.projet.model.kaosgoalmodel.KaosGoalModel.DomainProperty;
import vernotte.alexandre.idm.projet.model.kaosgoalmodel.KaosGoalModel.Expectation;
import vernotte.alexandre.idm.projet.model.kaosgoalmodel.KaosGoalModel.KaosGoalModelPackage;
import vernotte.alexandre.idm.projet.model.kaosgoalmodel.KaosGoalModel.Objective;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Alternative</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link vernotte.alexandre.idm.projet.model.kaosgoalmodel.KaosGoalModel.impl.AlternativeImpl#getFather <em>Father</em>}</li>
 *   <li>{@link vernotte.alexandre.idm.projet.model.kaosgoalmodel.KaosGoalModel.impl.AlternativeImpl#getRefinements <em>Refinements</em>}</li>
 *   <li>{@link vernotte.alexandre.idm.projet.model.kaosgoalmodel.KaosGoalModel.impl.AlternativeImpl#getExpectation <em>Expectation</em>}</li>
 *   <li>{@link vernotte.alexandre.idm.projet.model.kaosgoalmodel.KaosGoalModel.impl.AlternativeImpl#getDomainProperty <em>Domain Property</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class AlternativeImpl extends GoalModelElementImpl implements Alternative {
	/**
	 * The cached value of the '{@link #getFather() <em>Father</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getFather()
	 * @generated
	 * @ordered
	 */
	protected Objective father;

	/**
	 * The cached value of the '{@link #getRefinements() <em>Refinements</em>}' reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getRefinements()
	 * @generated
	 * @ordered
	 */
	protected EList refinements;

	/**
	 * The cached value of the '{@link #getExpectation() <em>Expectation</em>}' reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getExpectation()
	 * @generated
	 * @ordered
	 */
	protected EList expectation;

	/**
	 * The cached value of the '{@link #getDomainProperty() <em>Domain Property</em>}' reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getDomainProperty()
	 * @generated
	 * @ordered
	 */
	protected EList domainProperty;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected AlternativeImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected EClass eStaticClass() {
		return KaosGoalModelPackage.Literals.ALTERNATIVE;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Objective getFather() {
		if (father != null && father.eIsProxy()) {
			InternalEObject oldFather = (InternalEObject)father;
			father = (Objective)eResolveProxy(oldFather);
			if (father != oldFather) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, KaosGoalModelPackage.ALTERNATIVE__FATHER, oldFather, father));
			}
		}
		return father;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Objective basicGetFather() {
		return father;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetFather(Objective newFather, NotificationChain msgs) {
		Objective oldFather = father;
		father = newFather;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, KaosGoalModelPackage.ALTERNATIVE__FATHER, oldFather, newFather);
			if (msgs == null) msgs = notification; else msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setFather(Objective newFather) {
		if (newFather != father) {
			NotificationChain msgs = null;
			if (father != null)
				msgs = ((InternalEObject)father).eInverseRemove(this, KaosGoalModelPackage.OBJECTIVE__FATHER_ALTERNATIVES, Objective.class, msgs);
			if (newFather != null)
				msgs = ((InternalEObject)newFather).eInverseAdd(this, KaosGoalModelPackage.OBJECTIVE__FATHER_ALTERNATIVES, Objective.class, msgs);
			msgs = basicSetFather(newFather, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, KaosGoalModelPackage.ALTERNATIVE__FATHER, newFather, newFather));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList getRefinements() {
		if (refinements == null) {
			refinements = new EObjectWithInverseResolvingEList.ManyInverse(Objective.class, this, KaosGoalModelPackage.ALTERNATIVE__REFINEMENTS, KaosGoalModelPackage.OBJECTIVE__ALTERNATIVES);
		}
		return refinements;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList getExpectation() {
		if (expectation == null) {
			expectation = new EObjectWithInverseResolvingEList.ManyInverse(Expectation.class, this, KaosGoalModelPackage.ALTERNATIVE__EXPECTATION, KaosGoalModelPackage.EXPECTATION__ALTERNATIVES);
		}
		return expectation;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList getDomainProperty() {
		if (domainProperty == null) {
			domainProperty = new EObjectWithInverseResolvingEList.ManyInverse(DomainProperty.class, this, KaosGoalModelPackage.ALTERNATIVE__DOMAIN_PROPERTY, KaosGoalModelPackage.DOMAIN_PROPERTY__ALTERNATIVE);
		}
		return domainProperty;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case KaosGoalModelPackage.ALTERNATIVE__FATHER:
				if (father != null)
					msgs = ((InternalEObject)father).eInverseRemove(this, KaosGoalModelPackage.OBJECTIVE__FATHER_ALTERNATIVES, Objective.class, msgs);
				return basicSetFather((Objective)otherEnd, msgs);
			case KaosGoalModelPackage.ALTERNATIVE__REFINEMENTS:
				return ((InternalEList)getRefinements()).basicAdd(otherEnd, msgs);
			case KaosGoalModelPackage.ALTERNATIVE__EXPECTATION:
				return ((InternalEList)getExpectation()).basicAdd(otherEnd, msgs);
			case KaosGoalModelPackage.ALTERNATIVE__DOMAIN_PROPERTY:
				return ((InternalEList)getDomainProperty()).basicAdd(otherEnd, msgs);
		}
		return super.eInverseAdd(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case KaosGoalModelPackage.ALTERNATIVE__FATHER:
				return basicSetFather(null, msgs);
			case KaosGoalModelPackage.ALTERNATIVE__REFINEMENTS:
				return ((InternalEList)getRefinements()).basicRemove(otherEnd, msgs);
			case KaosGoalModelPackage.ALTERNATIVE__EXPECTATION:
				return ((InternalEList)getExpectation()).basicRemove(otherEnd, msgs);
			case KaosGoalModelPackage.ALTERNATIVE__DOMAIN_PROPERTY:
				return ((InternalEList)getDomainProperty()).basicRemove(otherEnd, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case KaosGoalModelPackage.ALTERNATIVE__FATHER:
				if (resolve) return getFather();
				return basicGetFather();
			case KaosGoalModelPackage.ALTERNATIVE__REFINEMENTS:
				return getRefinements();
			case KaosGoalModelPackage.ALTERNATIVE__EXPECTATION:
				return getExpectation();
			case KaosGoalModelPackage.ALTERNATIVE__DOMAIN_PROPERTY:
				return getDomainProperty();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case KaosGoalModelPackage.ALTERNATIVE__FATHER:
				setFather((Objective)newValue);
				return;
			case KaosGoalModelPackage.ALTERNATIVE__REFINEMENTS:
				getRefinements().clear();
				getRefinements().addAll((Collection)newValue);
				return;
			case KaosGoalModelPackage.ALTERNATIVE__EXPECTATION:
				getExpectation().clear();
				getExpectation().addAll((Collection)newValue);
				return;
			case KaosGoalModelPackage.ALTERNATIVE__DOMAIN_PROPERTY:
				getDomainProperty().clear();
				getDomainProperty().addAll((Collection)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void eUnset(int featureID) {
		switch (featureID) {
			case KaosGoalModelPackage.ALTERNATIVE__FATHER:
				setFather((Objective)null);
				return;
			case KaosGoalModelPackage.ALTERNATIVE__REFINEMENTS:
				getRefinements().clear();
				return;
			case KaosGoalModelPackage.ALTERNATIVE__EXPECTATION:
				getExpectation().clear();
				return;
			case KaosGoalModelPackage.ALTERNATIVE__DOMAIN_PROPERTY:
				getDomainProperty().clear();
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case KaosGoalModelPackage.ALTERNATIVE__FATHER:
				return father != null;
			case KaosGoalModelPackage.ALTERNATIVE__REFINEMENTS:
				return refinements != null && !refinements.isEmpty();
			case KaosGoalModelPackage.ALTERNATIVE__EXPECTATION:
				return expectation != null && !expectation.isEmpty();
			case KaosGoalModelPackage.ALTERNATIVE__DOMAIN_PROPERTY:
				return domainProperty != null && !domainProperty.isEmpty();
		}
		return super.eIsSet(featureID);
	}

} //AlternativeImpl
